﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace PrinterMonitorSvc.Common
{
    /// <summary>
    /// WebClient帮助类
    /// </summary>
    public class WebClientHelper : WebClient
    {

        static WebClientHelper()
        {
            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
            ServicePointManager.Expect100Continue = false;
            ServicePointManager.DefaultConnectionLimit = 512;
            ServicePointManager.UseNagleAlgorithm = false;
        }

        /// <summary>
        /// WebClient帮助类
        /// </summary>
        /// <param name="timeout">超时时间(以毫秒为单位)</param>
        public WebClientHelper(int timeout)
        {
            Timeout = timeout;
        }

        /// <summary>
        /// 超时时间(以毫秒为单位)
        /// </summary>
        public int Timeout { get; set; }

        protected override WebRequest GetWebRequest(Uri address)
        {
            var request = base.GetWebRequest(address);
            request.Timeout = Timeout;
            return request;

        }
    }
}
